package com.hcxdi.calanderapp.utils;

import java.util.Calendar;
import java.util.Date;

public class TimeUtils {
    public static boolean isSameDate(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);

        boolean isSameYear = cal1.get(Calendar.YEAR) == cal2
                .get(Calendar.YEAR);
        boolean isSameMonth = isSameYear
                && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
        boolean isSameDate = isSameMonth
                && cal1.get(Calendar.DAY_OF_MONTH) == cal2
                .get(Calendar.DAY_OF_MONTH);
        return isSameDate;
    }

    /**
     * 是否是过去的时间
     * @param date1 当前时间
     * @param date2
     * @return
     */
    public static boolean isOldDate(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);
        if (cal1.get(Calendar.YEAR)>cal2.get(Calendar.YEAR)){
            return true;
        }else if (cal1.get(Calendar.YEAR) == cal2
                .get(Calendar.YEAR)){
           if (cal1.get(Calendar.MONTH)>cal2.get(Calendar.MONTH)){
               return true;
           }else if (cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)){
               if (cal1.get(Calendar.DAY_OF_MONTH)>cal2.get(Calendar.DAY_OF_MONTH)){
                   return true;
               }else {
                   return false;
               }
           }else {
               return false;
           }
        }else {
            return false;
        }
    }

}
